<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.hs.pre.model.*" %>
<%@ page import="com.hs.pre.page.PageUtil" %>
<%@ page import="com.hs.utils.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
List list = new ArrayList(); 
PageUtil pageUtil = (PageUtil)request.getAttribute("pageUtil");
    list = pageUtil.getResultList();
%>

<html>
  <head>
    <base href="<%=basePath%>"> 
    <META content="MSHTML 6.00.2900.3268" name=GENERATOR> 
    <LINK href="<%=basePath%>app/css/default.css" type=text/css rel=stylesheet>
     <script src='<%=basePath%>app/js/json.js'></script>
     <script src='<%=basePath%>dwr/interface/indexer.js'></script>
     <script src='<%=basePath%>dwr/engine.js'></script>
     <script src='<%=basePath%>dwr/util.js'></script> 
     <script src='<%=basePath%>app/js/common.js'></script> 
     <script type="text/javascript">
     //添加索引
     function addIndex(){ 
	     var rows = document.getElementsByName("preId"); 
	     var dataStr = '[';
	     if(null != rows){ 
	        for(var i=0;i<rows.length;i++){
	            if(rows[i].checked){   
	               dataStr += dwr.util.getValue('data_'+rows[i].value)+"," ;  
	            }
	        }
	        dataStr = dataStr.substring(0,dataStr.length-1);
	     }
	     dataStr += ']';
	     if(dataStr.length>2){
		     var test = eval(dataStr);
		     //var stu = '[{"id":"2222","fangm":"ddddd"},{"id":"2222","fangm":"ddddd"}]';
		     indexer.addIndex(test,callBackAdd);
	     }else{ 
	        alert("请选择要更新的方剂");
	     }
	     
     }
     function callBackAdd(message){
       // alert(message);
        if(message != ""){
           var objs = message.split(',');
           if(null != objs && objs.length >0){
           		for(var i = 0;i<objs.length;i++){ 
           		   if(objs[i] != ""){
           		      var temp = objs[i];
           		      var arr = temp.split('@');
           		      if(null != arr && arr.length >0){
           		          dwr.util.setValue('zt_'+arr[0],arr[2]);
           		          dwr.util.setValue('sj_'+arr[0],arr[1]);
           		      }
           		   }
           		}
           
           }
        }
     }
     //更新索引
     function updateIndex(){
     
     }
     
     function callBackDel(data){
     
     }
     //删除索引
     function deleteIndex(){
     	if(confirm("确认删除所选方剂的索引？")){ 
	         var rows = document.getElementsByName("preId"); 
		     var dataStr = '';
		     if(null != rows){ 
		        for(var i=0;i<rows.length;i++){
		            if(rows[i].checked){   
		               dataStr += rows[i].value+"," ;  
		            }
		        }
		        dataStr = dataStr.substring(0,dataStr.length-1);
		     } 
		     if(dataStr != ''){  
			     indexer.deleteIndex(dataStr,callBackDel);
		     }else{ 
		        alert("请选择要删除的方剂");
		     }
	     }
     }
     //
     function updateIndexById(id){
        var dataStr ='['+dwr.util.getValue('data_'+id) + ']' ;
        var test = eval(dataStr); 
        indexer.addIndex(test,callBackUpdateById);
     }
     function callBackUpdateById(message){
         if(message != ""){
           var objs = message.split(',');
           if(null != objs && objs.length >0){
           		for(var i = 0;i<objs.length;i++){ 
           		   if(objs[i] != ""){
           		      var temp = objs[i];
           		      var arr = temp.split('@');
           		      if(null != arr && arr.length >0){
           		          dwr.util.setValue('zt_'+arr[0],arr[2]);
           		          dwr.util.setValue('sj_'+arr[0],arr[1]);
           		      }
           		   }
           		}
           
           }
        }
     
     }
      function deleteIndexById(id){ 
        indexer.deleteIndex(id,callBackDel);
     }
      function indexAll(){ 
      	if(confirm("本操作将会重建全部方剂索引，确认要重建吗？")){
        	indexer.indexAll(callBackAdd);
        }
     }
     
     function editPre(){
        var id = "";
        openwindow('../admin/editPre.jsp?preId='+id,'1200','800','_blank');
        //window.location.href="../admin/editPre.jsp";
     } 
     </script>
</HEAD>
<BODY>  
<form name="form1" action="" method="post">
<table cellSpacing=0 align=right cellPadding=0 border=0>
<tr>
<td>
<table   cellSpacing=0 align=right cellPadding=0 border=0 valign=top>
<tr> 
<td><input name="button" type="button" class="buttom" onclick="deleteIndex();" value="添加任务"></td>
<td><input name="button" type="button" class="buttom" onclick="indexAll();" value="删除任务"></td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr heigth="5px"><td><br></td></tr>
<tr>
<td>
<DIV class=tab>
<TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all; TEXT-ALIGN: justify" width=100% cellSpacing=0 cellPadding=0 border=0>
  <TBODY>
  <TR class=top>
    <TD width=3%>序号</TD> 
    <TD width=10%>任务描述</TD> 
    <TD width=40%>任务类型</TD> 
    <TD width=10%>开始时间</TD> 
    <TD width=10%>结束时间</TD> 
    <TD width=10%>耗时</TD> 
    <TD width=10%>任务状态</TD> 
     <TD width=10%>操作</TD> 
    </TR>
   <%
   if(null != list && list.size() >0){
   int size = list.size();
   for(int i=0;i<size;i++){
     JobEntry jobEntry =(JobEntry)list.get(i);
   %>
  <TR align=center bgColor=<%if(i%2 == 0){out.println("#fffbff");}else{out.println("#eef1f9");} %>>
    <TD><FONT color=#ff3300><%=i+1 %></FONT></TD> 
    <TD class=title><input type="checkbox" value="<%=jobEntry.getJobId()%>" name="preId"><%=Utilities.null2Blank(jobEntry.getJobDesc()) %></TD>
    <TD><%=Utilities.null2Blank(jobEntry.getJobType()) %></TD>
    <TD><%=jobEntry.getJobStart() %></TD>
    <TD><%=jobEntry.getJobEnd() %></TD>
    <TD><%=Utilities.null2Blank(jobEntry.getJobExeTime()) %></TD>
    <TD><%=Utilities.null2Blank(jobEntry.getJobStatus())%></TD>
    <TD>删除</TD> 
  </TR> 
    <%} }else{%>
    <TR align=middle bgColor="#eef1f9">
    <TD colspan=7 align="center"><FONT color=red>没有数据</FONT></TD> 
  </TR>  
    <%} %>
  </TBODY></TABLE>
  </DIV>
  </td>
  </tr> 
  <tr>
<td>
 <%=pageUtil.viewHTML() %>
 </td>
  </tr> 
 
</table>
</form>
<DIV class=clear></DIV>
</BODY></HTML>